package dragon.tagext.util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import dragon.core.util.StringUtils;

public class IncludePage extends SimpleTagSupport {

	private String path;

	@Override
	public void doTag() throws JspException, IOException {
		JspContext jspContext = getJspContext();

		if (StringUtils.isEmpty(path)) {
			return;
		} else {
			path = path.trim();
		}
		PageContext pageContext = (PageContext) jspContext;
		try {
			pageContext.include(path);
		} catch (ServletException e) {
			throw new JspException(e);
		}
	}

	public void setPath(String path) {
		this.path = path;
	}
}
